package singleton;

//doublecheck,类似于懒加载
public class CreatSingleton4 {
    private static CreatSingleton4 singleton;
    private CreatSingleton4() {
        System.out.println(Thread.currentThread().getName() + "正在调用构造方法");
    }
    public static CreatSingleton4 getSingleton() {
        if (singleton == null) {
            synchronized (CreatSingleton4.class) {
                if (singleton==null)
                    singleton = new CreatSingleton4();
            }
        }
        return singleton;
    }
    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                CreatSingleton4.getSingleton();
            },String.valueOf(i)).start();

        }
    }
}
